package com.yzy.fly.mapper;

import com.yzy.fly.entity.role.FlyComponent;
import com.yzy.fly.entity.role.FlyController;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FlyControllerMapper extends FlyBasicMapper<FlyController> {

    @Select("select * from fly_controller a where 1=1")
    List<FlyController> selectAll();

    @Select("select * from fly_controller a where 1=1 and a.systemId = #{systemId}")
    List<FlyController> selectAllBySystemId(@Param("systemId") int systemId);

//    @Select("select * from fly_controller a where 1=1 and a.componentId = #{componentId}")
//    List<FlyController> selectAllByComponentId(@Param("componentId") int componentId);

    @Select("select * from fly_controller a where 1=1 and a.parentId = #{parentId}")
    FlyController selectOneByComponentId(@Param("parentId") int parentId);

    @Select("select * from fly_controller a where 1=1 and a.parentId = #{parentId}")
    List<FlyController> selectAllByComponentId(@Param("parentId") int parentId);

    @Select("select * from fly_controller a where 1=1 and a.name = #{name}")
    FlyController selectOneByName(@Param("name") String name);

    @Select("select * from fly_controller a where systemId = #{systemId} order by a.packageName asc")
    List<FlyController> selectAllPackageNameAsc(@Param("systemId") Integer systemId);


    @Select({"",
        "select * from fly_component a where a.id in ",
        "(",
        "    select DISTINCT d.businessId from fly_process_node b,fly_process_line c,fly_process_node d where 1=1 ",
        "    and d.businessId is not null",
        "    and b.id =  c.`to`",
        "    and d.id =  c.`from`",
        "    and b.businessType = #{businessType}",
        "    and b.processId = c.processId",
        "    and b.processId = d.processId",
        "    and b.processId in (select e.id from fly_process e where e.id is not null and e.type = #{processType} and e.businessId in (select f.id from fly_interface f where f.componentId = #{componentId} ))",
        ")"
    })
    List<FlyComponent> selectAllFromBusinessIdByToBusinessId(@Param("processType") String processType, @Param("businessType") String businessType, @Param("componentId") int componentId);



}